package com.yt.hadoop.reducejoin;

/**
 * @Classname OrderReducer
 * @Description
 * @Date 2021/12/8 10:22
 * @Create by 杨涛
 */

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class OrderReducer extends Reducer<OrderBean, NullWritable, OrderBean, NullWritable> {

    Map<String,String> namemap=new HashMap<String, String>();
    @Override
    protected void reduce(OrderBean key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {

        String pname = key.getPname();
        System.out.println("key:"+key.toString()+"-pid:"+key.getPid()+"pname:"+key.getPname());
        if(pname!=null && !pname.equals(""))
            namemap.put(key.getPid(),key.getPname());
        else{
            pname=namemap.get(key.getPid());
            key.setPname(pname);
            System.out.println("写入一条数据===="+key );
            context.write(key,NullWritable.get());
        }

    }


}
